<?php
//项目管理

namespace app\admin\controller;

use app\admin\model\Projects as ProjectsM;

class Projects extends Base
{
    protected $middleware = ['app\admin\middleware\TableFields::class'];  //获取表结构，添加在返回数据中
    protected $lists_fields = 'id,title,company,status,projects_status,projects_time';
    public $index_not_display_fields = 'id,update_time,create_time,is_remake';
    public $additional_fields_list = [
        'schedule' =>['name' => 'schedule', 'comment' => '进度']
        ];
    public function filter(&$map, &$field)
    {
        $field = $this->lists_fields;
        //回收站
        $status = request()->get('status', 0);
        if($status == 3)
        {
            $map = [['status', '=', 3]];
        }else{
            $map = [['status', 'in', '1,2']];
        }

        //项目状态
        $projects_status = input('projects_status', 0);
        if(!empty($projects_status))
        {
            $map = [['projects_status', '=', $projects_status]];
        }

        //项目标题
        $title = input('title');
        if(!empty($title)){
            $map[] = ['title', 'like', '%'.$title.'%'];
        }
        //甲方公司
        $company = input('company');
        if(!empty($company)){
            $map[] = ['company', 'like', '%'.$company.'%'];
        }
        //项目时间
        $start_time = input('start_time', 0);
        $end_time = input('end_time', 0);


        if (!empty($end_time) && !empty($start_time)) {
            $map[] = ['projects_time', 'BETWEEN', [$start_time, $end_time]];
        } else if ($end_time) {
            $map[] = ['projects_time', '<', $end_time];
        } else if ($start_time) {
            $map[] = ['projects_time', '>', $start_time];
        }
    }

    public function beforeDetail(&$field)
    {

    }

    public function attachedIndex($data)
    {
        foreach($data as $k=>$v){
            //项目进度 查询项目下订单完成度
            $data[$k]['schedule'] = (new ProjectsM())->getProjectsSchedule($v['id']);
        }
        return $data;
    }

}